#include "./text_test.h"

/*
EXPECT_EQ - compara 2 objetos
EXPECT_TRUE - verifica se o parametro e true
EXPECT_FALSE - verifica se o parametro e false
EXPECT_STREQ - compara conteudo de 2 objetos do tipo char*
*/

TEST(Text, operatorAddition_string_and_string) {

	// Arrange
	string str1, final_str1;
	str1 = final_str1 = "abc"; // no change expected
	string str2, final_str2;
	str2 = final_str2 = "123"; // no change expected
	string expected = "abc123";

	// Act
	string actual = str1 + str2;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAdditionAndAttribution_string_and_string) {

	// Arrange
	string str1, final_str1;
	str1 = "abc"; final_str1 = "abc123!!"; // changes expected
	string str2, final_str2;
	str2 = final_str2 = "123"; // no change expected
	string str3, final_str3;
	str3 = final_str3 = "!!"; // no change expected
	string expected = "abc123!!";

	// Act
	string actual = ( (str1 += str2) += str3 );

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( str3, final_str3 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorAddition_string_and_charPtr) {

	// Arrange
	string str1, final_str1;
	str1 = final_str1 = "abc"; // no change expected
	string expected = "abc123";

	// Act
	string actual = str1 + "123";

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAddition_charPtr_and_string) {

	// Arrange
	string str1, final_str1;
	str1 = final_str1 = "abc"; // no change expected
	string expected = "123abc";

	// Act
	string actual = "123" + str1;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAdditionAndAttribution_string_and_charPtr) {

	// Arrange
	string str1, final_str1;
	str1 = "abc"; final_str1 = "abc123!!"; // changes expected
	string expected = "abc123!!";

	// Act
	string actual = ( (str1 += "123") += "!!" );

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, itos) {

	// Arrange
	int num, final_num;
	num = final_num = -1; // no changes expected
	string expected = "-1";

	// Act
	string actual = itos(num);

	// Assert
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, stoi) {

	// Arrange
	string str, final_str;
	str = final_str  = "-1"; // no changes expected
	int expected = -1;

	// Act
	int actual = Define::stoi(str);

	// Assert
	EXPECT_EQ( str, final_str );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorAddition_string_and_int) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	int num = -1, final_num = -1;
	string expected = "abc-1";

	// Act
	string actual = str1 + num;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAddition_int_and_string) {

	// Arrange
	int num = -1, final_num = -1;
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string expected = "-1abc";

	// Act
	string actual = num + str1;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAdditionAndAttribution_string_and_int) {

	// Arrange
	string str1 = "abc", final_str1 = "abc-12"; // no change expected
	int num1 = -1, final_num1 = -1;
	int num2 = 2, final_num2 = 2;
	string expected = "abc-12";

	// Act
	string actual = ( (str1 += num1) += num2 );

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num1, final_num1 );
	EXPECT_EQ( num2, final_num2 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, dtos) {

	// Arrange
	double num = -1.0, final_num = -1.0;
	string expected = "-1.0000";

	// Act
	string actual = dtos(num);

	// Assert
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, stod) {

	// Arrange
	string str = "-1.0000", final_str = "-1.0000";
	double expected = -1.0;

	// Act
	int actual = Define::stoi(str);

	// Assert
	EXPECT_EQ( str, final_str );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorAddition_string_and_double) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	double num = -1.0, final_num = -1.0;
	string expected = "abc-1.0000";

	// Act
	string actual = str1 + num;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAddition_double_and_string) {

	// Arrange
	double num = -1.0, final_num = -1.0;
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string expected = "-1.0000abc";

	// Act
	string actual = num + str1;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num, final_num );
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorAdditionAndAttribution_string_and_double) {

	// Arrange
	string str1 = "abc", final_str1 = "abc-1.00002.0000"; // no change expected
	double num1 = -1.0, final_num1 = -1.0;
	double num2 = 2.0, final_num2 = 2.0;
	string expected = "abc-1.00002.0000";

	// Act
	string actual = ( (str1 += num1) += num2 );

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( num1, final_num1 );
	EXPECT_EQ( num2, final_num2 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, file_scan_FILE) {

	// Arrange
	FILE *pFile;
	EXPECT_TRUE( file_open( "file.txt", pFile ) );

	string expected = "abc";

	EXPECT_TRUE( file_print( expected, pFile ) );
	EXPECT_TRUE( file_close( pFile ) );

	// Act
	EXPECT_TRUE( file_open( "file.txt", pFile, "r" ) );

	string actual = "";
	EXPECT_TRUE( file_scan( actual, pFile ) );

	EXPECT_TRUE( file_close( pFile ) );

	// Assert
	EXPECT_EQ( expected, actual );

};

TEST(Text, operatorEqual_string_and_string_true) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string str2 = "abc", final_str2 = "abc"; // no change expected
	bool expected = true;

	// Act
	bool actual = str1 == str2;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorEqual_string_and_string_false) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string str2 = "123", final_str2 = "123"; // no change expected
	bool expected = false;

	// Act
	bool actual = str1 == str2;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorNotEqual_string_and_string_false) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string str2 = "abc", final_str2 = "abc"; // no change expected
	bool expected = false;

	// Act
	bool actual = str1 != str2;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( expected, actual ); // real test

};

TEST(Text, operatorNotEqual_string_and_string_true) {

	// Arrange
	string str1 = "abc", final_str1 = "abc"; // no change expected
	string str2 = "123", final_str2 = "123"; // no change expected
	bool expected = true;

	// Act
	bool actual = str1 != str2;

	// Assert
	EXPECT_EQ( str1, final_str1 );
	EXPECT_EQ( str2, final_str2 );
	EXPECT_EQ( expected, actual ); // real test

};

using namespace Except;

void funct_throw(){
	throw Exception("Exception thrown.");
};

TEST(Exception, throwing) {

	try{
		funct_throw();
	}
	catch( Exception ){
		EXPECT_TRUE( true );
	}
	catch( ... ){
		EXPECT_TRUE( false );
	}

};

// To use a test fixture, derive a class from testing::Test.
class TextTest : public testing::Test {
	protected:  // You should make the members protected s.t. they can be
	// accessed from sub-classes.

	// virtual void SetUp() will be called before each test is run.  You
	// should define it if you need to initialize the variables.
	// Otherwise, this can be skipped.
	virtual void SetUp() {
		str1 = "abc"; str2 = "123"; str3 = "!!";
		int1 = -1; int2 = 2;
		num1 = -1.0; num2 = 2.0;
	}

	// virtual void TearDown() will be called after each test is run.
	// You should define it if there is cleanup work to do.  Otherwise,
	// you don't have to provide it.
	//
	virtual void TearDown() {
	}

	// A helper function that some test uses.
	static int Double(int n) {
		return 2*n;
	}

	// Declares the variables your tests want to use.
	string str1, str2, str3;
	string final_str1, final_str2, final_str3;
	int int1, int2;
	int final_int1, final_int2;
	double num1, num2;
	int final_num1, final_num2;
};

// When you have a test fixture, you define a test using TEST_F
// instead of TEST.

TEST_F(TextTest, fixture_example) {
	// You can access data in the test fixture here.
	EXPECT_EQ(str1, "abc");
	EXPECT_EQ(str2, "123");
	EXPECT_EQ(str1 + str2, "abc123");
	//EXPECT_TRUE( false ) << "Forced error!";
};
